﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TCHSHue.BLL;

namespace TCHSHue.Modules.AdminControl.User
{
    public partial class ctrUserCreate : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var user = (DAL.User)Session["userDangNhap"];
            if (user != null)
            {
                if (user.quyen != ((int)Quyen.Admin).ToString())
                {
                    Response.Redirect("Admin.aspx");
                }
            }
        }

        protected void bntThem_Click(object sender, EventArgs e)
        {
            thongBao.Visible = true;
            var tenDangNhap = Server.HtmlEncode(txtTenDangNhap.Text.Trim());
            var matKhau = Server.HtmlEncode(txtMatKhau.Text.Trim());
            var hoTen = Server.HtmlEncode(txtHoTen.Text.Trim());
            var email = Server.HtmlEncode(txtEmail.Text.Trim());
            if (UserBLL.create(tenDangNhap, matKhau, hoTen, email, ddlQuyen.SelectedValue))
            {
                lbThongBao.Text = "Thêm user thành công!";
                txtTenDangNhap.Text = "";
                txtMatKhau.Text = "";
                txtHoTen.Text = "";
                txtEmail.Text = "";
            }
            else
                lbThongBao.Text = "Thêm user thất bại!";
            txtTenDangNhap.Focus();
        }
    }
}